<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
	 <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <meta name="format-detection" content="telephone=no">
        <meta charset="UTF-8">
        <meta name="description" content="Violate Responsive Admin Template">
        <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">
        <link href="<%=path %>/assets2/js/bootstrap-table.css" rel="stylesheet">
        <script src="<%=path %>/assets2/js/jquery-1.11.1.min.js"></script>
        <script src="<%=path %>/assets2/js/bootstrap-table.js"></script>
   		<script src="<%=path %>/assets2/js/locale/bootstrap-table-zh-CN.js"></script>
   		<script src="<%=path %>/assets2/js/bootstrap.min.js"></script>
   		<script src="<%=path%>/assets2/js/bootstrap-datetimepicker.min.js"></script>
		<link rel="stylesheet" href="<%=path%>/assets2/js/bootstrap-datetimepicker.min.css">
		<script src="<%=path %>/assets2/js/jquery.timers-1.1.2.js"></script>
		
    </head>
    <body>
<div class="row">
	<ol class="breadcrumb">
		<li><a href="<%=path%>/index"><span
				class="glyphicon glyphicon-home"></span></a></li>
		<li class="active">资金管理</li>
	</ol>
</div>

<input type="hidden" id="settlementId">
<input type="hidden" id="merchantPrice">
<input type="hidden" id="openId">

<div class="panel panel-default">
	<div class="panel-heading">提现记录列表</div>
	<div class="panel-body">
	
		<div style="background-color: #E6E6FA;">
			<div class="layui-card"><br>
			  <div class="layui-card-body">
			  	<div class="row">
			  		<div class="col-md-3 col-md-offset-2" style="font-size: 18px;">可用余额:<span id="moneyNum">0</span></div>
			  		<div class="col-md-7">
			  			<div class="row">
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="请输入提现的金额">
							</div>			  			
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="请输入提现的备注">
							</div>			  			
							<div class="col-md-4">
								<button type="button" class="btn btn-primary" onclick="withdrawalBtn()">提现</button>
							</div>			  			
			  			</div>
			  		</div>
			  	</div>
			  	<br>
			  </div>
			</div>
		</div>
		
		<form id="formSearch" class="form-horizontal">
		<input type="hidden" id="systemMessage" name="systemMessage" value="1">
			<div class="form-group" style="margin-top: 15px">
				<label class="control-label col-sm-2" for="startTime">起始时间</label>
				<div class="col-sm-3">
					<div class='input-group date' id='datetimepicker1' style="">
						<input type='text' class="form-control" id="startTime"
							name="startTime" /> <span class="input-group-addon"
							style="cursor: pointer;"> <span
							class="glyphicon glyphicon-calendar"></span>
						</span>
					</div>
					<!-- <input type="text" class="form-control" name="serachGoodsName" > -->
				</div>
				<label class="control-label col-sm-2" for="endTime">结束时间</label>
				<div class="col-sm-3">
					<div class='input-group date' id='datetimepicker2'>
						<input type='text' class="form-control" id="endTime"
							name="endTime" /> <span class="input-group-addon"
							style="cursor: pointer;"> <span
							class="glyphicon glyphicon-calendar"></span>
						</span>
					</div>
				</div>
				<div class="col-sm-2" style="text-align: left;">
					<button type="button" style="margin-left: 50px" id="btn_query"
						class="btn btn-primary" onclick="serachUser()">查询</button>
				</div>
			</div>
		</form>
		<table id="tabId"></table>
	</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="myModal">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalTitle"></h4>
			</div>
			<div class="modal-body" id="myModalBody">
				
			</div>
		</div>
	 </div>
	</div>
   
   <script type="text/javascript">
   $(function () {
	    //1.初始化Table
	    var oTable = new TableInit();
	    oTable.Init();

	    //2.初始化Button的点击事件
	    var oButtonInit = new ButtonInit();
	    oButtonInit.Init();

		//日期选择
	    var picker1 = $('#datetimepicker1').datetimepicker({  
	        format: 'YYYY-MM-DD',  
	        locale: moment.locale('zh-cn'),  
	    });  
	    var picker2 = $('#datetimepicker2').datetimepicker({  
	        format: 'YYYY-MM-DD',  
	        locale: moment.locale('zh-cn')  
	    });  
	    getMoneyInfo();
	    
	});


	var TableInit = function () {
	    var oTableInit = new Object();
	    //初始化Table
	    oTableInit.Init = function () {
	        $('#tabId').bootstrapTable({
	            url: '<%=path %>/web/getCashDrawsInfoList',         //请求后台的URL（*）
	            method: 'get',                      //请求方式（*）
	            toolbar: '#toolbar',                //工具按钮用哪个容器
	            striped: false,                      //是否显示行间隔色
	            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
	            pagination: true,                   //是否显示分页（*）
	            sortable: false,                     //是否启用排序
	            sortOrder: "asc",                   //排序方式
	            queryParams: oTableInit.queryParams,//传递参数（*）
	            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
	            pageNumber:1,                       //初始化加载第一页，默认第一页
	            pageSize: 10,                       //每页的记录行数（*）
	            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
	            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
	            strictSearch: false,
	            showColumns: false,                  //是否显示所有的列
	            showRefresh: false,                  //是否显示刷新按钮
	            minimumCountColumns: 2,             //最少允许的列数
	            clickToSelect: false,                //是否启用点击选中行
	            uniqueId: "cashId",                     //每一行的唯一标识，一般为主键列
	            showToggle:false,                    //是否显示详细视图和列表视图的切换按钮
	            cardView: false,                    //是否显示详细视图
	            detailView: false,                   //是否显示父子表
	            columns: [/* {
	            	checkbox: true, // 显示一个勾选框
	                align: 'center', // 居中显示
	                
	            }, */ {
	                field: 'money',
	                title: '提现金额',
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            }, {
	                field: 'accType',
	                title: '提现方式',
	                align: 'center', // 左右居中
	                valign: 'middle', // 上下居中
	                formatter: accTypeFormatter
	            }, {
	                field: 'cashRemarks',
	                title: '提现备注',
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            }, {
	                field: 'cashSatus',
	                title: '提现状态',
	                align: 'center', // 左右居中
	                valign: 'middle', // 上下居中
	                formatter: cashSatusFormatter
	            }, {
	                field: 'createDate',
	                title: '创建时间',
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            }]
	        });
	    };
// ,{
// 	                field: 'ststemMessageId',
// 	                title: '操作',
// 	                align: 'center', // 左右居中
// 	                valign: 'middle', // 上下居中
// 	                formatter: operateFormatter //自定义方法，添加操作按钮
// 	            }
	    //得到查询的参数
	    oTableInit.queryParams = function (params) {
	        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
	            limit: params.limit,   //页面大小
	            offset: params.offset,  //页码
	            startTime: $("#startTime").val(),
	            endTime: $("#endTime").val(),
	        };
	        return temp;
	    };
	    return oTableInit;
	};
	//查询
	function serachUser() {
        $("#tabId").bootstrapTable('refresh',{pageNumber:1});
    };
	var ButtonInit = function () {
	    var oInit = new Object();
	    var postdata = {};
	    oInit.Init = function () {
	        //初始化页面上面的按钮事件
	    };
	    return oInit;
	};
	function accTypeFormatter(value, row, index) {//赋予的参数
		var str=''
		if(value==1){
			str="<span>支付宝</span>"
        }else if(value==2){
        	str='<span>微信</span>'
        }else{
        	str='<span>银行卡</span>'
        }
	    return str;
	}
	function cashSatusFormatter(value, row, index){
		var str=''
		if(row==0){
			str="<span>待处理</span>"
        }else if(row==1){
        	str="<span>成功</span>"
        }else{
        	str="<span>失败</span>"
        }
	    return str;
	}
	function operateFormatter(value, row, index) {//赋予的参数
		var str=''
		if(row.ifRead==1){
			str=''
		}else{
			str='<a class="btn btn-default" href="#" onclick="ifRead('+value+')">预览</a>&nbsp;&nbsp;'
		}
	    return str;
	}
	function serachUser() {
        $("#tabId").bootstrapTable('refresh');
    }
	function ifRead(id){
		swal({ 
			  title: "是否确定删除？", 
			  type: "warning",
			  showCancelButton: true, 
			  confirmButtonColor: "#DD6B55",
			  confirmButtonText: "确定预览！", 
			  cancelButtonText: "取消预览！",
			  closeOnConfirm: false, 
			  closeOnCancel: true
			},
			function(isConfirm){ 
			    if(isConfirm){
			    	$.ajax({
						 type:"POST",
				         url: "<%=path %>/web/ifReadSystemMessage?ststemMessageId="+id,
				         success: function(data,status,xhr){
				        	 if(data.state==1){
				        		 $("#tabId").bootstrapTable('refresh');
				        	 }else{
				        	 }
				         }
					})
			    }
			});
	}
	//获取提现的金额
	function getMoneyInfo(){
		$.ajax({
			 type:"POST",
	         url: "<%=path %>/web/getOrderSettlementsInfo",
	         success: function(data,status,xhr){
	        	 if(data.orderSettlements==null||data.orderSettlements==''){
	        		 $("#merchantPrice").val(null);
		        	 $("#settlementId").val(null);
		        	 $("#openId").val(null);
		        	 $('body').everyTime('3s',queryOrder);
	        	 }else{
	        		 if(data.orderSettlements.openId==null||data.orderSettlements.openId==""){
	        			 $('body').everyTime('3s',queryOrder);
	        		 }
	        		 $("#merchantPrice").val(data.orderSettlements.merchantPrice);
	        		 $("#moneyNum").text(data.orderSettlements.merchantPrice);
		        	 $("#settlementId").val(data.orderSettlements.settlementId);
		        	 $("#openId").val(data.orderSettlements.openId);
	        	 }
	         }
		})
	}
	
	//提现按钮
	function withdrawalBtn(){
		var openId =$("#openId").val();
		if(openId==null||openId==""){
			$.ajax({
		    	url: "<%=path %>/common/createWxQRPay",
		        timeout: 300000,
		        dataType: "json",
		        type: "get",
		        success : function(data) {
		        	var ewmurl ="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data="+data;
		        	//页面层
		        	var ewHtml = '<img alt="" src="'+ewmurl+'">';
		        	layer.open({
		        	  type: 1,
		        	  title:"购买服务",
		        	  skin: 'layui-layer-rim', //加上边框
		        	  area: ['180px', '220px'], //宽高
		        	  content: ewHtml
		        	});
		        },error : function() {
		        }
		    })
		}else{
			
		}
	}
	//查询是否扫码成功
	function queryOrder(){
		var settlementId = $("#settlementId").val();
		$.ajax({
	    	url: "<%=path %>/common/queryWebWXPayState",
	        timeout: 300000,
	        data: {"settlementId":settlementId},
	        dataType: "json",
	        type: "get",
	        success : function(data) {
	        	if(data.mapWXResult!=null&&data.mapWXResult!=''){
	        		if(data.mapWXResult.trade_state=='SUCCESS'){
	        			$("#openId").val(data.mapWXResult.openid);
		        		$('body').stopTime(); 
		        		layer.closeAll();
		        		swal({ 
							  title: "操作成功", 
							  text: "购买提现服务成功", 
							  type: "success",
						});
		        	}else if(data.mapWXResult.trade_state=='NOTPAY'){
		        	}else if(data.mapWXResult.trade_state=='CLOSED'){
		        	}else if(data.mapWXResult.trade_state=='REVOKED'){
		        	}else if(data.mapWXResult.trade_state=='PAYERROR'){
		        	}
	        	}
	        },error : function() {
	        	layer.closeAll();
        		swal({ 
					  title: "操作失败", 
					  text: "网络错误", 
					  type: "error",
				});
	        }
	    })
	};
   </script>
   </body>
</html>